What's causing "NoMethodError: undefined method `include?' for nil:NilClass"

Posted by NudeCanalTroll on Stack Overflow See other posts from Stack Overflow or by NudeCanalTroll
Published on 2010-04-07T15:42:07Z Indexed on 2010/04/07 15:43 UTC
Read the original article Hit count: 170

Filed under:
|
|
|
|

I have a Book model in my Rails application, with various properties (aka columns in the book db table). One of these properties is "ranking".

Recently, may app has started to throw NoMethodError: undefined method 'include?' for nil:NilClass for the following code:

def some_method(book, another_arg)
  return book.ranking unless book.ranking.blank?
  ...
end

However, it's not consistent. The vast majority of the time, accessing book.ranking works -- the error is thrown maybe 2-4% of the time. If I change the code to book[:ranking] or book['ranking'] instead of book.ranking, it works 100% of the time.

Any ideas?

© Stack Overflow or respective owner

Related posts about ruby

Related posts about rails